package com.jintoufs.weixin.common;

import com.jintoufs.domain.constants.Constants;
import com.jintoufs.domain.sys.Dictionary;
import com.jintoufs.service.sys.DictionaryService;
import org.cosmos.modules.web.msg.AjaxMsg;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;

/**
 * Created by pengyang on 2018/3/18.
 */

@RestController
@RequestMapping("/api/common")
public class CommonAction {

    @Resource
    private DictionaryService dictionaryService;

    @GetMapping("/transFee")
    @ResponseBody
    public AjaxMsg transFee(){
        AjaxMsg ajaxMsg = new AjaxMsg();
        try{
            Dictionary dictionary = dictionaryService.getDicByKeyNo(Constants.DEFALUT_TRANS_FEE).get(0);
            ajaxMsg.setDatas(dictionary.getKeyValue());
            ajaxMsg.setMessage("OK");
        }catch (Exception e){
            e.printStackTrace();
            ajaxMsg.setCode(AjaxMsg.FAILURE);
            ajaxMsg.setMessage("获取默认邮费出错");
        }
        return ajaxMsg;
    }

    @GetMapping("/sxFee")
    @ResponseBody
    public AjaxMsg sxFee(String total){
        AjaxMsg ajaxMsg = new AjaxMsg();
        try{
            Integer totalFee = Integer.valueOf(total);
            Dictionary dictionary = dictionaryService.getDicByKeyNo(Constants.DEFALUT_SX_FEE).get(0);
            ajaxMsg.setDatas(totalFee * Double.valueOf(dictionary.getKeyValue()));
        }catch (Exception e){
            e.printStackTrace();
            ajaxMsg.setCode(AjaxMsg.FAILURE);
            ajaxMsg.setMessage("获取手续费失败");
        }
        return ajaxMsg;
    }
}
